unit fGlsLSystem;

interface

uses
  Winapi.Windows,
  Winapi.Messages,
  System.SysUtils,
  System.Classes,
  Vcl.Graphics,
  Vcl.Controls,
  Vcl.Forms,
  Vcl.Dialogs,
  Vcl.StdCtrls,
  Vcl.Buttons,
  Vcl.ExtCtrls,
  Vcl.ComCtrls;

type
  TLSystemForm = class(TForm)
    Panel1: TPanel;
    Label85: TLabel;
    Label89: TLabel;
    TPIEdit: TEdit;
    TCircledEdit: TEdit;
    TDegreeEdit: TEdit;
    TAxiomEdit: TEdit;
    Label129: TLabel;
    TKanEdit: TEdit;
    Label90: TLabel;
    TPruleEdit: TEdit;
    TurtleUpDown: TUpDown;
    Label5: TLabel;
    Label6: TLabel;
    TStrLenEdit: TEdit;
    Label105: TLabel;
    TProjEdit: TEdit;
    TurtleRG: TRadioGroup;
    DOfLevelEdit: TEdit;
    Label138: TLabel;
    Label101: TLabel;
    TXMinEdit: TEdit;
    Label102: TLabel;
    TYMinEdit: TEdit;
    Label103: TLabel;
    TZxmaxEdit: TEdit;
    Label104: TLabel;
    TZymaxEdit: TEdit;
    TClearBtn: TSpeedButton;
    TFileOpen: TSpeedButton;
    TurtleFileEdit: TEdit;
    TFileSave: TSpeedButton;
    TMouseBtn: TSpeedButton;
    THelpBtn: TBitBtn;
    TurtleOK: TBitBtn;
    Splitter1: TSplitter;
    ScrollBox1: TScrollBox;
    LSystemImage: TImage;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    procedure TurtleUpDownClick(Sender: TObject; Button: TUDBtnType);
    procedure TClearBtnClick(Sender: TObject);
    procedure TFileOpenClick(Sender: TObject);
    procedure TFileSaveClick(Sender: TObject);
    procedure TMouseBtnClick(Sender: TObject);
    procedure THelpBtnClick(Sender: TObject);
    procedure TurtleOKClick(Sender: TObject);
  private
  public
  end;

var
  LSystemForm: TLSystemForm;
  TKan, Axiom: string;
  FYImageX, FYImageY, TurtleLevel, TPI, TCircled, TDegrees, TurtleDirN, TXminI,
    TmaxI, TYminI, TYmaxI: Integer;
  ProductionRules: array [1 .. 52] of string;

implementation

uses
  uTurtlep;

{$R *.DFM}

procedure TLSystemForm.TurtleUpDownClick(Sender: TObject; Button: TUDBtnType);
begin
  (* if (Button = btNext) then begin
    if ((TurtleLevel + 1) < 52) then
    SelectNextTurtleFun(Button = btNext)
    end
    else begin if ((TurtleLevel - 1) >= 1) then
    SelectNextTurtleFun(Button = btNext); end;
  *)
  { When Button is btPrev, the Down or Left arrow was clicked,
    and the value of Position is about to decrease by Increment. }
end;

procedure TLSystemForm.TClearBtnClick(Sender: TObject);
var
  i, code: Integer;
  SizeStr: string;
begin
  TPIEdit.Text := 'Turtle.FLA';
  TProjEdit.Text := '';
  for i := 1 to 52 do
  begin
    ProductionRules[i] := '';
    TurtleUpDown.Position := 1;
    TurtleLevel := 1;
    Axiom := '';
    TAxiomEdit.Text := Axiom;
    TKan := '';
    TKanEdit.Text := TKan;
    { TPI:Extended; }
    TPIEdit.Text := '0';
    val(TPIEdit.Text, TPI, code);
    { Codefx(TPIEdit.Text, Code); }
    { TCircledEdit:Extended; }
    TCircledEdit.Text := '0';
    val(TCircledEdit.Text, TCircled, code);
    { Codefx(TCircledEdit.Text,   Code); }
    { TDegrees:Extended; }
    TDegreeEdit.Text := '0';
    val(TDegreeEdit.Text, TDegrees, code);
    { Codefx(TDegreeEdit.Text,   Code); }
    TurtleRG.ItemIndex := 0;
    { TXminI }
    TXMinEdit.Text := '0';
    val(TXMinEdit.Text, TXminI, code);
    { Codefx(TXMinEdit.Text, Code); }
    { TYminI }
    TYMinEdit.Text := '0';
    val(TYMinEdit.Text, TYminI, code);
    { Codefx(TYMinEdit.Text, Code); }
    { TmaxI }
    str(FYImageX, SizeStr);
    TZxmaxEdit.Text := SizeStr;
    val(TZxmaxEdit.Text, TmaxI, code);
    { Codefx(TZxmaxEdit.Text, Code); }
    { TYmaxI:Integer; }
    str(FYImageY, SizeStr);
    TZymaxEdit.Text := SizeStr;
    val(TZymaxEdit.Text, TYmaxI, code);
    { Codefx(TZymaxEdit.Text,   Code); }
  end;
end;

procedure TLSystemForm.TFileOpenClick(Sender: TObject);
var
  MyFilesS: string;
begin { Display Open dialog box }
  { OpenDialog1.InitialDir:=FormulasDir; }
  OpenDialog1.Filter := 'Turtle (*.FLA)|*.FLA';
  OpenDialog1.Filename := TurtleFileEdit.Text;
  if OpenDialog1.Execute then
  begin
    MyFilesS := Uppercase(ExtractFileExt(OpenDialog1.Filename));
    { FormulasDir:=ExtractFilePath(OpenDialog1.FileName); }
    if MyFilesS = '.FLA' then
    begin
      MyFilesS := ExtractFileName(OpenDialog1.Filename);
      TurtleFileEdit.Text := MyFilesS;
      { TurtleLoadDo(OpenDialog1.FileName); }
    end;
  end;
end;

procedure TLSystemForm.TFileSaveClick(Sender: TObject);
var
  MyFilesS: string;
  fTurtleFile: TextFile;
  TurtleLeveled, code: Integer;
begin { Display Open dialog box }
  { SaveDialog1.InitialDir:=FormulasDir; }
  SaveDialog1.Filter := 'Turtle (*.FLA)|*.FLA';
  SaveDialog1.Filename := TurtleFileEdit.Text;
  if SaveDialog1.Execute then
  begin
    MyFilesS := Uppercase(ExtractFileExt(SaveDialog1.Filename));
    { FormulasDir:=ExtractFilePath(SaveDialog1.FileName); }
    if MyFilesS = '.FLA' then
    begin
      MyFilesS := ExtractFileName(SaveDialog1.Filename);
      TurtleFileEdit.Text := MyFilesS;
      AssignFile(fTurtleFile, SaveDialog1.Filename);
      Rewrite(fTurtleFile);
      if IoResult <> 0 then
      begin
        { DoMessages(30103); }
      end
      else
      begin { Write Turtle files }
        { Axiom:String; }
        Axiom := TAxiomEdit.Text;
        Writeln(fTurtleFile, Axiom);
        { TKan:String; }
        TKan := TKanEdit.Text;
        Writeln(fTurtleFile, TKan);
        { Get Turtle(TurtleLevel); }
        TurtleLeveled := TurtleRG.ItemIndex;
        str(TurtleLeveled, MyFilesS);
        Writeln(fTurtleFile, MyFilesS);
        { TurtleLevel:=TurtleLeveled; }
        { TPI:Extended; } Writeln(fTurtleFile, TPIEdit.Text);
        val(TPIEdit.Text, TPI, code);
        { Codefx(TPIEdit.Text, Code); }
        { TCircled:Extended; }
        Writeln(fTurtleFile, TCircledEdit.Text);
        val(TCircledEdit.Text, TCircled, code);
        { Codefx(TCircledEdit.Text, Code); }
        { TDegrees:Extended; } Writeln(fTurtleFile, TDegreeEdit.Text);
        val(TDegreeEdit.Text, TDegrees, code);
        { Codefx(TDegreeEdit.Text, Code); }
        { TXminI } Writeln(fTurtleFile, TXMinEdit.Text);
        val(TXMinEdit.Text, TXminI, code);
        { Codefx(TXMinEdit.Text,     Code); }
        { TYminI } Writeln(fTurtleFile, TYMinEdit.Text);
        val(TYMinEdit.Text, TYminI, code);
        { Codefx(TYMinEdit.Text,    Code); }
        { TmaxI } Writeln(fTurtleFile, TZxmaxEdit.Text);
        val(TZxmaxEdit.Text, TmaxI, code);
        { Codefx(TZxmaxEdit.Text,   Code); }
        { TYmaxI:Integer; } Writeln(fTurtleFile, TZymaxEdit.Text);
        val(TZymaxEdit.Text, TYmaxI, code);
        { Codefx(TZymaxEdit.Text,  Code); }
        { Get Turtle(TurtleLevel); }
        ProductionRules[TurtleLevel] := TProjEdit.Text;
        for code := 1 to 52 do
        begin
          { ProductionRules:Array [0..127] of String; }
          Writeln(fTurtleFile, ProductionRules[code]);
        end;
      end;
      CloseFile(fTurtleFile);
    end;
  end;
end;
(* ************************************************ *)
(* ************************************************ *)

procedure TLSystemForm.TMouseBtnClick(Sender: TObject);
begin
  { bMousing := (not bMousing); }
end;

procedure TLSystemForm.THelpBtnClick(Sender: TObject);
begin
  // Application.HelpContext(3100); {Turtle}
end;

procedure TLSystemForm.TurtleOKClick(Sender: TObject);
begin
  { MainForm.DoImageStart;
    TurtleRun;
    Mainform.DoImageDone; }
end;

end.
